package com.twu.biblioteca;

import java.util.ArrayList;

public class Library {
    private ArrayList<Book> books;
    private ArrayList<Movie> movies;

    Library() {
        books = new ArrayList<Book>();
        movies = new ArrayList<Movie>();
    }

    public boolean attemptBookReservation(int bookIndex) {
        if (bookIndex >= 0 && bookIndex < books.size())
            if (!books.get(bookIndex).isReserved()) {
                books.get(bookIndex).reserve();
                return true;
            }
        return false;
    }

    public void addBook(Book book) {
        books.add(book);
    }

    public boolean isBookReserved(int bookIndex) {
        return books.get(bookIndex).isReserved();
    }

    public void addMovie(Movie movie) {
        movies.add(movie);
    }

    public String getBooksString() {
        return getStringOfAL(books);
    }

    public String getMoviesString() {
        return getStringOfAL(movies);
    }

    //why bother todo: out of domain
    public String getStringOfAL(ArrayList<? extends Object> list) {
        String retString = "";
        for (int i=0; i<list.size(); i++) {
            retString += list.get(i).toString() + "\n";
        }
        return retString;
    }

    public String[] getBooksArray() {
        String[] stringBookArray = new String[books.size()];
        for (int i=0; i<books.size(); i++) {
            stringBookArray[i] = books.get(i).toString();
        }
        return stringBookArray;
    }
}